
#-------------------------------------------------------------------
# Project:     Assult on the over world
# Name:        game.py
# Purpose:     An Enemy Object
# 
# Authors:     Chris Lheureux, Matt Hahn, Tyler Plante, Jackson Morse
# Main Author: Jackson Morse
#
# Created:     5/3/13
# Copyright:   (c) 
# License:     GSL
#-------------------------------------------------------------------
import pygame, math, random

class BaseEnemy(pygame.sprite.Sprite):
    def _init_(self, speed, position, screenSize):
        pygame.sprite.Sprite.__init__(self, self.containers)
        self.images = []
        self.frame = 0
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.radius = self.rect.width/2.4
        speed = [1, 1]
        self.maxSpeed = 2
        self.speed = speed
        self.detectionRadius = 1000
        self.noSpeed = 0
        self.place(position)
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.living = True
   
    def __str__(self):
        return "I am the BASE" + str(self.rect.center) + str(self.speed) + str(self.unDead)
    
    def place(self, position):
        self.rect.center = position
   
    def move(self):
        self.rect = self.rect.move(self.speed)
            
        
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
        #print "I'm near something ", str(other.rect.center)
        
    def chase(self, player):
        if self.distToPoint(player.rect.center) < self.detectionRadius:
            pX = float(player.rect.center[0])
            pY = float(player.rect.center[1])
            myX = float(self.rect.center[0])
            myY = float(self.rect.center[1])
            
            if myX < pX and myY == pY:
                angle = 0
                #print "+X"
            elif myX < pX and myY > pY: #Quad 1
                diffX = (pX - myX)
                diffY = (pY - myY)*-1
                self.angle = math.degrees(math.atan(diffY/diffX))
                #print "Qaud 1"
                #print "(", diffX, ",", diffY, ")", self.angle
            elif myX == pX and myY > pY:
                angle = 90
                #print "+Y"
            elif myX > pX and myY > pY: #Quad 2
                diffX = (pX - myX)
                diffY = (pY - myY)*-1
                self.angle = 180 - math.degrees(math.atan(diffY/diffX * -1))
                #print "Qaud 2"
                #print "(", diffX, ",", diffY, ")", self.angle
            elif myX > pX and myY == pY:
                angle = 180
                #print "-X"
            elif myX > pX and myY < pY:
                diffX = (pX - myX)
                diffY = (pY - myY)*-1
                self.angle = 180 + math.degrees(math.atan(diffY * -1/diffX * -1))
                #print "Qaud 3"
                #print "(", diffX, ",", diffY, ")", self.angle
            elif myX == pX and myY < pY:
                self.angle = 270
                #print "-Y"
            elif myX < pX and myY < pY:
                diffX = (pX - myX)
                diffY = (pY - myY)*-1
                self.angle = 360 - math.degrees(math.atan(diffY * -1/diffX))
                #print "Qaud 4"
                #print "(", diffX, ",", diffY, ")", self.angle
    
        
    def collideBlock(self, screenWidth, screenHeight):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.speed[0] = self.speed[0]*-1
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.speed[1] = self.speed[1]*-1
            
   
        
    def collidePlayer(self, Enemy):
        if (self.rect.right > Enemy.rect.left 
            and self.rect.left < Enemy.rect.right):
            if (self.rect.bottom > Enemy.rect.top and 
                self.rect.top < Enemy.rect.bottom):
                if (self.distToPoint(Enemy.rect.center)
                    < self.radius + Enemy.radius):  
                    self.speed[0] = self.speed[0] * -1
                    self.speed[1] = self.speed[1] * -1
                    Enemy.speed[0] = Enemy.speed[0] * -1
                    Enemy.speed[1] = Enemy.speed[1] * -1
                    return True

    
    def Player(self, Player):
        if self.distToPoint(Player.rect.center) < self.biteRadius:
            pX = Player.rect.center[0]
            pY = Player.rect.center[1]
            zX = self.rect.center[0]
            zY = self.rect.center[1]
            
            if pX > zX:
                self.speed[0] = self.noSpeed
                Player.life = Player.life -1 
            elif pX < zX:
                self.speed[0] = -self.noSpeed
                Player.life = Player.life -1
            else:
                self.speed[0] = 0
        
            if pY > zY:
                self.speed[1] = self.noSpeed
                Player.life = Player.life -1 
            elif pY < zY:
                self.speed[1] = -self.noSpeed
                Player.life = Player.life -1    
            else:
                self.speed[1] = 0  
    def update():
        self.move()
        self.wallCollide()

    def Die(self):
        if self.life <= 0:
            self.living = False
